package root

import (
	"fmt"
	"goProject/db"
	"net/http"

	"gitee.com/ruige_fun/util/std"
	"github.com/kataras/iris/v12"
)

func config(c iris.Context) {
	all, _ := db.RunConfig.GetAll()
	c.JSON(std.NewResp(http.StatusOK, "", all, len(all)))
}

type pConfigSave struct {
	TokenSecond int `json:"token_second" validate:"required,min=600,max=86400"`
}

// configSave 保存设置
func configSave(c iris.Context) {
	var p pConfigSave
	err := c.ReadBody(&p)
	if err != nil {
		c.JSON(std.NewResp(http.StatusBadRequest, "参数校验失败", nil, nil))
		return
	}
	_ = db.RunConfig.Set("登录Token有效时间（秒）：", fmt.Sprint(p.TokenSecond))
	c.JSON(std.NewResp(http.StatusOK, "", nil, nil))
}
